import "./index.scss";
import { useNavigate, useLocation } from "react-router-dom";
import { Form, Modal, message } from "antd";
import TextArea from "antd/es/input/TextArea";
import { useState } from "react";
import http from "../../../utils/http";

const Particulars = () => {
  //取数据
  const state = useLocation();
  console.log("state", state.state);

  //返回上一个页面
  const navigate = useNavigate();
  const back = () => {
    navigate("/home/BusinessLicense");
  };

  //时间转换
  const toDub = (n: any) => (n < 10 ? "0" + n : "" + n);
  //年月日时分秒
  const toTime = (date: any) => {
    const oTime = new Date(date);
    return (
      oTime.getFullYear() +
      "-" +
      toDub(oTime.getMonth() + 1) +
      "-" +
      toDub(oTime.getDate()) +
      " " +
      toDub(oTime.getHours()) +
      ":" +
      toDub(oTime.getMinutes()) +
      ":" +
      toDub(oTime.getSeconds())
    );
  };
  //年月日
  const toDate = (date: any) => {
    const oDate = new Date(date);
    return (
      oDate.getFullYear() +
      "-" +
      toDub(oDate.getMonth() + 1) +
      "-" +
      toDub(oDate.getDate())
    );
  };

  //通过
  const [isModalOpen11, setIsModalOpen11] = useState(false);
  //不通过
  const [isModalOpen22, setIsModalOpen22] = useState(false);

  // 弹框通过
  const [val11] = Form.useForm();
  const showModal11 = (record: any) => {
    val11.setFieldsValue({ ...record });
    setIsModalOpen11(true);
  };
  const handleOk11 = () => {
    http({
      url: "/passTwo",
      method: "post",
      data: {
        id: state.state.id,
        obstate: "待审批",
      },
    }).then((res: { [key: string]: any }) => {
      if (res.error == 0) {
        message.success("通过成功");
        setIsModalOpen11(false);
        navigate("/home/BusinessLicense");
      } else {
        message.error("通过失败");
      }
    });
  };
  const handleCancel11 = () => {
    setIsModalOpen11(false);
  };

  //   弹框不通过
  const [val22] = Form.useForm();
  const showModal22 = (record: any) => {
    val22.setFieldsValue({ ...record });
    setIsModalOpen22(true);
  };
  const handleOk22 = () => {
    const data22 = val22.getFieldsValue(true);
    http({
      url: "/nopassTwo",
      method: "post",
      data: {
        id: state.state.id,
        obstate: "待审批",
        obno: data22.obno,
      },
    }).then((res: { [key: string]: any }) => {
      if (res.error == 0) {
        message.success("不通过成功");
        setIsModalOpen22(false);
        navigate("/home/BusinessLicense");
      } else {
        message.error("不通过失败");
      }
    });
  };
  const handleCancel22 = () => {
    setIsModalOpen22(false);
  };

  return (
    <div className="student-detail">
      <div className="top">
        <div className="title" onClick={back}>
          营业执照管理
        </div>
        <div>&gt;</div>
        <div className="detail">详情</div>
      </div>

      <div className="hr"></div>
      <div className="context-box">
        <img
          src={state.state.olicense}
          style={{
            width: "200px",
            height: "300px",
            border: "1px solid #ccc",
            display: "inline-block",
          }}
        ></img>
        <div className="context">
          <div className="tr">
            <div className="td1">备案机构</div>
            <div className="td2">{state.state.oname}</div>
          </div>
          <div className="tr">
            <div className="td">办学范围</div>
            <div>{state.state.orange}</div>
          </div>
          <div className="tr">
            <div className="td">证件类型</div>
            <div>营业执照</div>
          </div>
          <div className="tr">
            <div className="td">组织代码机构</div>
            <div>{state.state.ocode}</div>
          </div>
          <div className="tr">
            <div className="td">到期时间</div>
            <div>{toDate(state.state.oexpire)}</div>
          </div>
          <div className="tr">
            <div className="td">提交时间</div>
            <div>{toTime(state.state.otime)}</div>
          </div>
        </div>
      </div>
      <div className="box-div">
        <div className="one" onClick={showModal22}>
          不通过
        </div>
        <div className="two" onClick={showModal11}>
          通过
        </div>
      </div>

      {/* 弹框通过*/}
      <Modal
        title="通过"
        open={isModalOpen11}
        onOk={handleOk11}
        onCancel={handleCancel11}
        okText={"确认"}
        cancelText={"取消"}
      >
        <Form form={val11}>
        <div>是否同意该机构的营业执照信息？</div>
        </Form>
      </Modal>

      {/* 弹框不通过 */}
      <Modal
        title="不通过"
        open={isModalOpen22}
        onOk={handleOk22}
        onCancel={handleCancel22}
        okText={"确认"}
        cancelText={"取消"}
      >
        <Form form={val22}>
          <Form.Item name="obno">
            <TextArea rows={4} placeholder="请输入不同意理由" />
          </Form.Item>
        </Form>
      </Modal>
    </div>
  );
};
export default Particulars;
